package com.pe1n.yangtaopai.page.home.presenter;

import android.util.Log;

import com.pe1n.yangtaopai.bean.BrandBean;
import com.pe1n.yangtaopai.bean.FindBean;
import com.pe1n.yangtaopai.bean.MultiTitleBean;
import com.pe1n.yangtaopai.bean.NewsBean;
import com.pe1n.yangtaopai.bean.OtherBean;
import com.pe1n.yangtaopai.bean.PreferenceBean;
import com.pe1n.yangtaopai.bean.RecommendBean;
import com.pe1n.yangtaopai.bean.SingleTitleBean;
import com.pe1n.yangtaopai.bean.SpecialBean;
import com.pe1n.yangtaopai.bean.TypeBean;
import com.pe1n.yangtaopai.page.home.modle.IModle;
import com.pe1n.yangtaopai.page.home.modle.ModleImpl;
import com.pe1n.yangtaopai.page.home.view.interfacese.IView;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/22.
 */

public class PresenterImpl implements IPresenter{

    private IModle mModle;
    private IView mView;

    public PresenterImpl(IView view) {
        this.mModle = new ModleImpl();
        this.mView = view;
    }

    @Override
    public void loadMultiTitleData(String url) {
        mModle.getMultiTitleBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MultiTitleBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onNext(MultiTitleBean multiTitleBean) {
                        mView.loadMultiTitleData(multiTitleBean);
                    }
                });
    }

    @Override
    public void loadSingleTitleData(String url) {

        mModle.getSingleTitleBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SingleTitleBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(SingleTitleBean singleTitleBean) {
                        mView.loadSingleTitleData(singleTitleBean);
                    }
                });

    }

    @Override
    public void loadBrandData(String url) {

        mModle.getBrandBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BrandBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(BrandBean brandBean) {
                        mView.loadBrandData(brandBean);
                    }
                });

    }

    @Override
    public void loadFindData(String url) {

        mModle.getFindBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FindBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(FindBean findBean) {
                        mView.loadFindData(findBean);
                    }
                });

    }

    @Override
    public void loadNewsData(String url) {

        mModle.getNewsBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<NewsBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(NewsBean newsBean) {
                        mView.loadNewsData(newsBean);
                    }
                });

    }

    @Override
    public void loadOtherData(String url) {

        mModle.getOtherBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OtherBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(OtherBean otherBean) {
                        mView.loadOtherData(otherBean);
                    }
                });

    }

    @Override
    public void loadPreferenceData(String url) {

        mModle.getPreferenceBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PreferenceBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(PreferenceBean preferenceBean) {
                        mView.loadPreferenceData(preferenceBean);
                    }
                });

    }

    @Override
    public void loadRecommendData(String url) {

        mModle.getRecommendBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<RecommendBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(RecommendBean recommendBean) {
                        mView.loadRecommendData(recommendBean);
                    }
                });

    }

    @Override
    public void loadTypeData(String url) {

        mModle.getTypeBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<TypeBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(TypeBean typeBean) {
                        mView.loadTypeData(typeBean);
                    }
                });

    }

    @Override
    public void loadSpecialData(String url) {

        mModle.getSpecialBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SpecialBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(SpecialBean specialBean) {
                        mView.loadSpecialData(specialBean);
                    }
                });

    }

}
